package com.example.administrator.mywebviewdemo;

import android.net.http.SslError;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RelativeLayout;

import com.just.library.AgentWeb;

import org.json.JSONObject;

public class Main2Activity extends AppCompatActivity {
    private AgentWeb mAgentWeb;
    private RelativeLayout mRelativeLayout;
    private WebSettings webSettings;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();

        mAgentWeb = AgentWeb.with(this)//
                .setAgentWebParent(mRelativeLayout,new RelativeLayout.LayoutParams(-1,-1) )//
                .useDefaultIndicator()//
                .setIndicatorColor(ContextCompat.getColor(Main2Activity.this,R.color.colorAccent))
//                .setReceivedTitleCallback(mCallback)
                .setWebChromeClient(mWebChromeClient)
                .setWebViewClient(new WebViewClient() {
                    @Override
                    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                        handler.proceed();
                    }

                })
                .setSecutityType(AgentWeb.SecurityType.strict)
                .createAgentWeb()//
                .ready()
                .go("https://www.baidu.com");
        webSettings =  mAgentWeb.getAgentWebSettings().getWebSettings();
        webSettings.setUseWideViewPort(false);
        webSettings.setMinimumFontSize(6);
        mAgentWeb.getWebCreator().get().addJavascriptInterface(new HomeClickResult(), "nativeMethod");

    }
    private class HomeClickResult {

        JSONObject obj = null;

        /**
         * banner点击事件
         *
         * @param activityId
         * @return
         */
        @JavascriptInterface
        public String bannerSkip(String activityId) {
//            equalNetWork();
            Log.e("XXX", "bannerSkip:" + activityId);
            return null;
        }}
    private WebChromeClient mWebChromeClient=new WebChromeClient(){
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            //do you work
//            Log.i("Info","progress:"+newProgress);
        }
    };
    /**
     *
     */
    private void initView() {
        mRelativeLayout = (RelativeLayout) findViewById(R.id.rl);
    }
}
